home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 2_6.lha / 2_6 / 2_6.c next >
C/C++ Source or Header  |  1993-08-08  |  652b  |  39 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / print the bits of a null character pointer
  6. include <stream.h>
  7. include <limits.h>
  8.  
  9. include "2_6a.c"    /* EXPAND */
  10.  
  11. include "2_6c.c"    /* EXPAND */
  12.  
  13. oid prbits(char byte)
  14.  
  15.    cout << "0b";
  16.  
  17.    for (unsigned long mask = HIBIT(unsigned char);
  18.  mask != 0; mask >>= 1)
  19. if ((byte & mask) != 0)
  20.     cout << "1";
  21.  
  22. else
  23.     cout << "0";
  24.  
  25.  
  26. nt main(int, char**)
  27.  
  28. include "2_6b.c"    /* EXPAND4 */
  29.  
  30.    for (int i = 0; i < sizeof(char*); i++)
  31. {
  32. cout << "byte " << i << " = ";
  33. prbits(pi.byte[i]);
  34. cout << "\n";
  35. }
  36.  
  37.    return 0;
  38.  
  39.